package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.ShareBean;
import com.dingwei.superiordiary.mvp.presenter.SharePresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.weight.TitleBar;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.utils.SocializeUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created time 2018/3/12.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class FXYHLActivity extends BaseActivity implements Contract.ShareView {

    SharePresenter sharePresenter = new SharePresenter(this);
    @Bind(R.id.title_bar)
    TitleBar titleBar;
    @Bind(R.id.tv_guize)
    TextView tvGuize;
    @Bind(R.id.ll_wx)
    LinearLayout llWx;
    @Bind(R.id.ll_circle)
    LinearLayout llCircle;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fxyjf;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.ll_wx, R.id.ll_circle, R.id.ll_qq, R.id.ll_qq_kongjian, R.id.tv_guize})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_wx:
                sharePresenter.initData("weixin");
                break;
            case R.id.ll_circle:
                sharePresenter.initData("circle");
                break;
            case R.id.ll_qq:
                sharePresenter.initData("qq");
                break;
            case R.id.ll_qq_kongjian:
                sharePresenter.initData("qq_kongjian");
                break;
            case R.id.tv_guize:
                intent = new Intent(BaseActivity.context, JLGZActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void share(ShareBean bean, String type) {

        UMWeb web;
        web = new UMWeb(bean.getData().getSharp_url());
        web.setTitle(bean.getData().getSharp_title());
        web.setDescription("优品日记");
        if (TextUtils.isEmpty(bean.getData().getSharp_icon())) {
            web.setThumb(new UMImage(context, R.drawable.pic45));
        } else {
            web.setThumb(new UMImage(context, bean.getData().getSharp_icon()));
        }
        web.setDescription(bean.getData().getSharp_desc());

        switch (type) {
            case "weixin":
                new ShareAction(context)
                        .withText("")
                        .withMedia(web)
                        .setPlatform(SHARE_MEDIA.WEIXIN)
                        .setCallback(shareListener).share();
                break;
            case "circle":
                new ShareAction(context)
                        .withText("")
                        .withMedia(web)
                        .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                        .setCallback(shareListener).share();
                break;
            case "qq":
                new ShareAction(context)
                        .withText("")
                        .withMedia(web)
                        .setPlatform(SHARE_MEDIA.QQ)
                        .setCallback(shareListener).share();
                break;
            case "qq_kongjian":
                new ShareAction(context)
                        .withText("")
                        .withMedia(web)
                        .setPlatform(SHARE_MEDIA.QZONE)
                        .setCallback(shareListener).share();
                break;
        }


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    private UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            SocializeUtils.safeShowDialog(dialog);
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            SocializeUtils.safeCloseDialog(dialog);

        }
    };
}
